﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8"/>
    <title>批量处理</title>
    <link href="../Scripts/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="../Scripts/bootstrap/css/font-awesome.css" rel="stylesheet" />
    <link href="../Scripts/bootstrap/bootstrap-table/src/bootstrap-table.css" rel="stylesheet" type="text/css" />
    <link href="../Scripts/bootstrap/css/style.min.css" rel="stylesheet"  type="text/css" media="all" />
	
    <!--jquery-->
    <script src="../Scripts/jquery-1.11.0.min.js" type="text/javascript"></script>
    <script src="../Scripts/bootstrap/js/bootstrap.min.js" type="text/javascript" ></script>
    <script src="./JS/layer/layer.js" type="text/javascript"></script>
    <link href="./JS/layer/layer.css"  rel="stylesheet"  type="text/css"/>

    <!--bootstrap-table-->
    <script src="../Scripts/bootstrap/bootstrap-table/src/bootstrap-table.js" type="text/javascript"></script>
    <script src="../Scripts/bootstrap/bootstrap-table/src/locale/bootstrap-table-zh-CN.js" type="text/javascript"></script>
    <script src="../Scripts/bootstrap/bootstrap-paginator/js/bootstrap-paginator.js" type="text/javascript"></script>
    <script src="../Scripts/bootstrap/BootstrapUIDialog.js" type="text/javascript"></script>
    
    <!--公共JS-->
    <script src="../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../Scripts/config.js" type="text/javascript"></script>
    <script src="Gener.js" type="text/javascript"></script>
    <script language="JavaScript" src="JScript.js" type="text/javascript"></script>
    <script src="../Comm/JS/Calendar/WdatePicker.js" type="text/javascript"></script>
    <link href="../Comm/JS/Calendar/skin/WdatePicker.css" rel="stylesheet" type="text/css" />
    <script src="../Admin/CCFlowEnum.js" type="text/javascript"></script>   
    
     <base target="_self" />
     <style type="text/css">
          .fixed-table-container thead th 
             {
                padding: 8px;
                line-height: 24px;
                vertical-align: top;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
                background-color: #f2f2f2;
                width:100%;
            }
            .fixed-table-header
            {
               background-color: #f2f2f2; 
            }
          .input-group-addon {
            padding: 6px 3px;
            font-size: 14px;
            font-weight: 400;
            line-height: 1;
            color: #555;
            text-align: center;
            background-color: white; 
            border: 0;
            border-radius: 4px;
      }
       table
        {
            border-collapse: collapse; 
        }
            
        td{
            width:100%;
            word-break:keep-all;/* 不换行 */
            white-space:nowrap;/* 不换行 */
            overflow:hidden;/* 内容超出宽度时隐藏超出部分的内容 */
            text-overflow:ellipsis;/* 当对象内文本溢出时显示省略标记(...) ；需与overflow:hidden;一起使用*/
            -o-text-overflow:ellipsis;
            -icab-text-overflow: ellipsis;
            -khtml-text-overflow: ellipsis;
            -moz-text-overflow: ellipsis;
            -webkit-text-overflow: ellipsis;
        }
        
         .pagination > .active > a, 
        .pagination > .active > span
        {
           z-index:3;
           cursor:default;
           background-color:#fff;
           border-color:#ddd;
           color:#337ab7;
        } 
        .pagination > li > a, .pagination > li > span
        {
            color:#337ab7;
        } 
        a, a:link, a:visited
        {
            font-weight:normal
        }
        
         body
         {
             margin:0px;
         }
         .panel-header,
         .panel-body {
          border-width: 1px;
          border-top:0px;
          border-left:0px;
          border-right:0px;
         }
        
        table{table-layout:fixed;}

        table>td{width:100%}
         .Wdate {
            border: 1px solid #e5e6e7;
            height: 28px;
          }
       
     </style>
    <script language="javascript" type="text/javascript" >

        //定义公共个变量.
        var webUser = new WebUser();

        var ensName = GetQueryString("EnsName");

        //当前用户页面信息.
        var ur = new Entity("BP.Sys.UserRegedit");
        ur.MyPK = webUser.No + "_" + ensName + "_SearchAttrs";
        ur.RetrieveFromDBSources();
        var count = ur.GetPara("RecCount");
        var mapBase;
        var pageIdx = this.GetQueryString("PageIdx");
        var pageSize = 10;

        //页面启动函数.
        $(function () {

            if (webUser.No == undefined) {
                alert('登录信息丢失，请重新登录。');
                return;
            }
            if (ensName == null || ensName == undefined) {
                $("#Msg").html("必要的参数EnsName没有传入.");
                return;
            }
            $("#Msg").html("<img src=../Img/loading.gif />&nbsp;正在加载,请稍后......");

            $("#dialogExpFile").hide();
            //初始化工具栏.
            InitToolbar();

             if (pageIdx == null || pageIdx == "" || pageIdx == undefined)
                pageIdx = 1;
            //执行查询.
            BindTable();
            var pageCount = parseInt((count) / 10) + 1;
            //分页设计
            Paginator(pageCount, pageIdx);

            //批处理事件的获取
            BatchMethod();

            $("#Msg").html("");
             $("td").on("mouseover",function() {
                if (this.offsetWidth < this.scrollWidth) {
                    var that = this;
                    var text = $(this).text();
                   layer.tips(text, that,{
                        tips: 1,
                        time: 0
                   });
                }
              });
              $("td").on("mouseout",function(){
                layer.closeAll();
              });
        });

        //初始化数据.
        function InitToolbar() {

            //创建处理器.
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Comm");
            handler.AddUrlData();  //增加参数.

            //获得map基本信息.
            mapBase = handler.DoMethodReturnJSON("Search_MapBaseInfo");

            // $("#Title").html(mapBase.EnDesc); 
            document.title = mapBase.EnDesc;

            //获得查询信息，包含了查询数据表.
            var data = handler.DoMethodReturnJSON("Search_SearchAttrs");

            var html = "";
            if (mapBase.IsShowSearchKey == "1"){
                html +='<div class="form-group">';
                html +='<label class="sr-only" for="TB_Key">关键字</label>';
                html +='<div class="input-group">';
                html +='<div class="input-group-addon">关键字</div>';
                html +='<input type="text" class="form-control" name="TB_Key" id="TB_Key" value=\"" + ur.SearchKey + "\">';
                html +='</div>';
                html +='</div>';
            }
            if (mapBase.DTSearchWay != "0") {

                html +='<div class="form-group">';
                html +='<label class="sr-only">'+mapBase.DTSearchLable+'</label>';
                html +='<div class="input-group">';
                html +='<div class="input-group-addon">'+mapBase.DTSearchLable+'</div>';
               
                if (mapBase.DTSearchWay == "1") {
                    html +="<input type='text' class='form-control Wdate' name='TB_DTFrom' id='TB_DTFrom' value='" + ur.DTFrom + "'  onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd'})\" style='width:120px'>";
                    html +='</div>';
                    html +='</div>';
                    html +='<div class="form-group">';
                    html +='<label class="sr-only">到</label>';
                    html +='<div class="input-group">';
                    html +='<div class="input-group-addon">到</div>';
                    html +="<input type='text' class='form-control Wdate' name='TB_DTTo' id='TB_DTTo' value='" + ur.DTFrom + "'  onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd'})\" style='width:120px'>"; 
                } else {
                    html +="<input type='text' class='form-control Wdate' name='TB_DTFrom' id='TB_DTFrom' value='" + ur.DTFrom + "'  onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'})\" style='width:135px'>";
                     html +='</div>';
                    html +='</div>';
                    html +='<div class="form-group">';
                    html +='<label class="sr-only">到</label>';
                    html +='<div class="input-group">';
                    html +='<div class="input-group-addon">到</div>';
                    html +="<input type='text' class='form-control Wdate' name='TB_DTTo' id='TB_DTTo' value='" + ur.DTFrom + "'  onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'})\" style='width:135px'>";
                }
                html +='</div>';
                html +='</div>';
            }

            //绑定外键枚举查询条件.
            var attrs = data["Attrs"];

            //格式为: @WFSta=0@FK_Dept=02
            var json = AtParaToJson(ur.Vals);
            for (var i = 0; i < attrs.length; i++) {

                var attr = attrs[i];
                var str = "";
                str += "<div class='form-group'>";
                str += "<label class='sr-only' for='DDL_" + attr.Field + "'>" + attr.Name + "</label>";
                str += "<div class='input-group'>";
                str += "<div class='input-group-addon'>" + attr.Name + "</div>";
                str += "<select class='form-control' name='DDL_" + attr.Field + "' id='DDL_" + attr.Field + "'>" + InitDDLOperation(data, attr, "all") + "</select>";
                str += "</div>";
                str += "</div>";
                str = $(str);
                $("#toolbar").prepend(str); //设置基础信息.
            }
             $("#toolbar").prepend(html); //设置基础信息.

            //为查询外键赋值.
            for (var i = 0; i < attrs.length; i++) {
                var attr = attrs[i];
                var selectVal = json[attr.Field];

                if (selectVal == undefined || selectVal == "")
                    selectVal = "all";

                $("#DDL_" + attr.Field).val(selectVal);
            }

            if (mapBase.IsInsert == "True") {
                $("#NewWin").show();
            } else {
                $("#NewWin").hide();
            }

            if(new WebUser().No != "admin")
                $("#SetingBtn").hide();

        }

        //初始化下拉列表框的OPERATION
        function InitDDLOperation(frmData, mapAttr, defVal) {

            var operations = "";
            operations += "<option value='all' >全部</option>";

            var ens = frmData[mapAttr.Field];

           
            //ens为null时则为枚举类型
            if(ens==null){
                ens=[{'IntKey':0,'Lab':'否'},{'IntKey':1,'Lab':'是'}];
            }

            for (var i = 0; i < ens.length; i++) {

                var en = ens[i];

                if (en.No == undefined)
                    operations += "<option value='" + en.IntKey + "'>" + en.Lab + "</option>";
                else
                    operations += "<option value='" + en.No + "'>" + en.Name + "</option>";
            }
            return operations;
        }

        //执行查询.
        function Search(pageIdx) {

            //保存查询条件.
            var ensName = GetQueryString("EnsName");
            var ur = new Entity("BP.Sys.UserRegedit");
            ur.MyPK = webUser.No + "_" + ensName + "_SearchAttrs";
            ur.FK_Emp = webUser.No;

            if ($("#TB_Key") != null && $("#TB_Key").val() != "")
                ur.SearchKey = $("#TB_Key").val();
            else
                ur.SearchKey = "";

            //设置查询时间.
            if ($("#TB_DTFrom").length == 1)
                ur.DTFrom = $("#TB_DTFrom").val();

            if ($("#TB_DTTo").length == 1)
                ur.DTTo = $("#TB_DTTo").val();

            //获得外键的查询条件,存储里面去.
            var str = "";
            $("select[name^='DDL_']").each(function () {
                var id = $(this).attr("id");
                id = id.replace("DDL_", "");
                str += "@" + id + "=" + $(this).val();
            });

            ur.FK_Emp = webUser.No;
            ur.CfgKey = "SearchAttrs";
            ur.Vals = str;
            ur.FK_MapData = ensName;
            var i = ur.Save();

            var data = SearchData();
            $("#bsTable").bootstrapTable("load",data["DT"]);

             if (pageIdx == null || pageIdx == "" || pageIdx == undefined)
             pageIdx = 1;

              var pageCount = parseInt((count) / 10) + 1;
               //分页设计
               Paginator(pageCount, pageIdx);
        }

        //获取查询数据
        function SearchData() {
            //创建处理器.
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Comm");
            handler.AddPara("DoWhat" ,"Batch");
            handler.AddPara("EnsName", GetQueryString("EnsName"));
             handler.AddPara("PageIdx", pageIdx);
            handler.AddPara("PageSize", pageSize);
            //查询集合
            var data = handler.DoMethodReturnString("Search_SearchIt");
            if (data.indexOf('err@') == 0) {
                alert(data);
                return;
            }

            data = JSON.parse(data);
            //当前用户页面信息.
            var ur = new Entity("BP.Sys.UserRegedit");
            ur.MyPK = webUser.No + "_" + ensName + "_SearchAttrs";
            ur.RetrieveFromDBSources();

            count = ur.GetPara("RecCount");
            return data;
        }

        //生成Easyui DataGrid列表页面..
        function BindTable() {
        //获取页面的高度
            var H = document.body.clientHeight;
            var tableH = H-$("#toolbar").outerHeight()-$("#page-nav").outerHeight()-60;

            var mapdata = SearchData();

            var attrs = mapdata["Attrs"];

            if (attrs == undefined) {
                alert('没有取得属性.');
                return;
            }

            var keyOfEn = "";

            var columns = new Array(); 
            columns.push({
                        field: "ck",
                        fixed: false,
                        checkbox:true,
                        width:60,
                        singleSelect:false,

                    });
            for (var i = 0; i < attrs.length; i++) {
                var attr = attrs[i];

                if (attr.UIVisible == 0
                || attr.KeyOfEn == "OID"
                || attr.KeyOfEn == "WorkID"
                || attr.KeyOfEn == "NodeID"
                || attr.KeyOfEn == "MyNum"
                || attr.KeyOfEn == "MyPK") {
                    keyOfEn = attr.KeyOfEn
                    continue;
                }


                var field = attr.KeyOfEn;
                var title = attr.Name;
                if (attr.UIContralType == 1)
                    field = field + "Text";
                if (attr.UIContralType == 2)
                    columns.push({
                        field: field,
                        title: title,
                        fixed: false,
                        formatter: function (value, row, index) {
                            if (value == "0") return "否";
                            if (value == "1") return "是";

                        }
                    });
                else{
                var width = attr.Width;
                if(width==null || width==""|| width==undefined)
                        width = 180;
                    columns.push({
                        field: field,
                        title: title,
                        width:width,
                        fixed: false,
                    });
                }
            }


            var data = mapdata["DT"];
            $('#bsTable').bootstrapTable({
                data: data,
                columns: [columns],
                fitColumns: false,
                fit: true,
                rownumbers: true,
                striped: true,
                height:tableH,
                singleSelect: false,
                checkOnSelect:false,
                selectOnCheck:false,
                onDblClickRow: function (row, $element) {
                    var pkval = row["No"];
                    var objectID = "No";
                    if (pkval == undefined) {
                        pkval = row["OID"];
                        objectID = "OID";
                    }
                    if (pkval == undefined) {
                        pkval = row["MyPK"];
                        objectID = "MyPK";
                    }
                    if (pkval == undefined) {
                        pkval = row["WorkID"];
                        objectID = "WorkID";
                    }
                    if (pkval == undefined) {
                        pkval = row["NodeID"];
                        objectID = "NodeID";
                    }
                    var paras = "&" + objectID + "=" + pkval;
                    for (var i = 0; i < attrs.length; i++) {
                        var attr = attrs[i];
                        if (attr.UIContralType == 1)
                            paras += "&" + attr.KeyOfEn + "=" + row[attr.KeyOfEn];
                    }

                    OpenEn(pkval, paras);
                }

            });
        }

        //分页功能
        function Paginator(pageCount,currentPage) {
            var pageCount = pageCount; //取到pageCount的值(把返回数据转成object类型)
            var options = {
                bootstrapMajorVersion: 3, //版本
                currentPage: currentPage, //当前页数
                totalPages: pageCount, //总页数
                shouldShowPage: true, //是否显示该按钮
                itemTexts: function (type, page, current) {
                    switch (type) {
                        case "first":
                            return "首页";
                        case "prev":
                            return "上一页";
                        case "next":
                            return "下一页";
                        case "last":
                            return "末页";
                        case "page":
                            return page;
                    }
                }, //点击事件，用于通过Ajax来刷新整个list列表
                onPageClicked: function (event, originalEvent, type, page) {
                    pageIdx = page;
                    SearchData(page);
                }
            };
            $('#useroption').bootstrapPaginator(options);
        }

       

        //批处理事件的获取
          function  BatchMethod(){
            //创建处理器.
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Comm");
            handler.AddPara("EnsName", GetQueryString("EnsName"));
            //查询集合
            var data = handler.DoMethodReturnString("Refmethod_BatchInt");
             if (data.indexOf('err@') == 0) {
                alert(data);
                return;
            }
  
            var refMethods = JSON.parse(data);
            if(refMethods.length==0) return;

            var html="<table id='Table1' align='left'  border=0 width='100%'>";
            html +="<tr class='TRSum'  border=0>"
            html +="<td>"
                
            for(var i =0;i<refMethods.length;i++){
                var en = refMethods[i];
                html+="<input type='button' class='btn btn-default' value='"+en.Title+"' onclick='operateBatch(\"" + en.RefMethodType + "\",\"" + en.Url + "\",\"" + en.Title + "\",\"" + en.Warning + "\",\"" + en.W + "\",\"" + en.H + "\")'/>";
            }
            $("#refMethod").html(html);
          }

          //点击事件
           function operateBatch(methodType,url,title,warning,width,height) {
               //获取前台页面的复选框的值
            var pkValue = GetChecked();
            if(pkValue==null || pkValue==""){
                alert("请选择要执行的行");
                return;
            }
 
            url =  url.replace(/PKVal=/g,"PKVal="+pkValue);

            if (parseInt(methodType) == RefMethodType.Func) {
                  if (warning == "null" || warning == "")
                     warning="您确定要执行吗?";
                   
                else {
                    warning = warning.replace(/,\s+/g, ",");
                    warning = warning.replace(/\s+/g, "\r\n");
                }
                    if (confirm("\"" + warning + "\"")) {
                        OpenBootStrapModal(url,"eudlgframe", title, width,height,"icon-property", null, null, null, null, null, 'black');
                    }
                
            }else{
                OpenBootStrapModal(url,"eudlgframe", title , width, height,"icon-property", null, null, null, null, null, 'black');
            } 
        }

         //获取选中的行内容
       function GetChecked(){
        var checkedItems = $('#bsTable').bootstrapTable('getSelections');
  
        var names ="";
        $.each(checkedItems, function(index, item){
           var pkval = item.No;
           if (pkval == null || pkval == undefined)
           pkval = item.OID;

           if (pkval == null || pkval == undefined)
           pkval = item.WorkID;

            if (pkval == null || pkval == undefined)
           pkval=item.NodeID;

            if (pkval == null || pkval == undefined)
           pkval=item.MyNum; 

           if (pkval == null || pkval == undefined)
           pkval=item.MyPK;

           names = names+pkval+",";
            
        });              
            return names.substring(0,names.length-1);
       }

        //导出EXCEL表
       function Exp() {
             var handler = new HttpHandler("BP.WF.HttpHandler.WF_Comm");
            handler.AddPara("EnsName", GetQueryString("EnsName"));
            //查询集合
            var data = handler.DoMethodReturnString("Search_Exp");
            var url = "";
            if (data.indexOf('err@') == 0) {
                alert(data);
            }
            if (plant != 'CCFlow') {
                var currentPath = window.document.location.href;
                var path = currentPath.substring(0, currentPath.indexOf('/WF') + 1);
                data = path + data;
            }
            window.open(data);
            return;

        }


        //打开明细表
        function OpenEn(pk, paras) {
            //var select_row = $('#bsTable').bootstrapTable('getSelections');
            var ensName = GetQueryString("EnsName");
            var enName = ensName.substring(0, ensName.length - 1);

            var cfg = new Entity("BP.Sys.EnCfg");
            cfg.No = ensName;
            cfg.RetrieveFromDBSources();

            var url = cfg.GetPara("WinOpenUrl");

            if (url == "" || url == undefined) {
                url = "./RefFunc/En.htm?EnName=" + mapBase.EnName + "&PKVal=" + pk;
            }
            else {
                if (url.indexOf('?') == -1)
                    url = url + "?1=1";
                url = url + "&EnsName=" + ensName + "&enName=" + enName + "&PKVal=" + pk + paras;
            }

            var windowW = cfg.GetPara("WinCardW");
            if (windowW == "" || windowW == undefined)
                windowW = 700;

            var windowH = cfg.GetPara("WinCardH");
            if (windowH == "" || windowH == undefined)
                windowH = 500;

            var localUrl = window.location.href;
            

             OpenBootStrapModal(url, "eudlgframe", mapBase.EnDesc + ' : 详细', windowW, windowH, "icon-property", null, null,  null, function () {
                window.location.href = localUrl;
            },null,'black');
        }

        function New() {
            OpenEn("");


        }

        //跳转到设置页面
        function Setting() {
           var user = new WebUser();
            var url = "./Sys/SearchSetting.htm?EnsName=" + GetQueryString("EnsName") + "&m=" + Math.random();
            //获取屏幕的长宽
           var W = document.body.clientWidth-40;
           var H = document.body.clientHeight-40;
           OpenBootStrapModal(url, "eudlgframe", '设置', W, H, "icon-property", null, null, null, null, null, 'black'); 
        }

    </script>
</head>
<body>
<div style="padding: 0px 10px 0px 10px">
    <div >
        <div class="table-responsive">
            <div style="margin-bottom:5px">
                <div class="form-inline" id="toolbar">
                  <button type="button" class="btn btn-primary btn-sm" onclick="Search()">查询</button>
                  <button id="NewBtn"type="button" class="btn btn-default  btn-sm" onclick="New()">新建</button>
                  <button type="button" class="btn btn-default  btn-sm" onclick="Exp()">导出</button>
                  <button id="SetingBtn"type="button" class="btn btn-default  btn-sm"onclick="Setting()">设置</button>
                </div>
            </div>
            <table id="bsTable"  class="table table-hover"></table>
            <div id="refMethod"  style="margin-top:5px"></div>
        </div>
    </div>
</div>
</body>
</html>
